// pages/index/component/hotpost/hotpost.js
import {
  articleCategoryList,
  friendLink,
  articleList
} from '../../../../api/article.js'
import {
  getInfo
} from '../../../../api/mch'
const app = getApp()
import util from '../../../../utils/util'
Component({
  /**
   * 组件的属性列表
   */
  lifetimes: {
    attached() {
      this.setNavSize()
      this.loadHead()
      articleList({
        pageNum: 1,
        articleType: 1,
        sortField:'orders',
        direction:'desc',
      }).then(res => {
        res.data.data.forEach(item => {
          this.data.titles.push(item.title)
        })
        this.data.hotpost = res.data.data
        this.setData({
          titles: this.data.titles,
          hotpost: this.data.hotpost
        })
      })
    }
  },
  properties: {
    info: {
      type: Object
    }
  },

  pageLifetimes: {
    ready() {
      this.triggerEvent('getCanHeight')
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
    hotpost: [],
    titles: [],
    logo: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    toDetail(e) {
      let dataset = e.currentTarget.dataset
      if (dataset.linkType === 1) {
        wx.navigateTo({
          url: '/pages/member/webview/index?url=' + dataset.linkAddress,
        })
      } else {
        wx.navigateTo({
          url: '/pages/hotspot/hotspot/index?id=' + e.currentTarget.dataset.id,
        })
      }
    },
    loadHead() {
      getInfo(app.globalData.mchId).then(res => {
        res.data.logo = util.thumbnail(res.data.logo, 125, 125)
        this.data.logo = res.data.logo

        this.setData({
          logo: this.data.logo
        })
      })
    },
    searchClick() {
      wx.navigateTo({
        url: '/pages/goods/search/index'
      })
    },
    setNavSize: function () {
      var that = this,
        sysinfo = wx.getSystemInfoSync(),
        statusHeight = sysinfo.statusBarHeight,
        isiOS = sysinfo.system.indexOf('iOS') > -1,
        navHeight;
      console.log(sysinfo)
      if (!isiOS) {
        navHeight = 48;
      } else {
        navHeight = 44;
      }
      that.setData({
        status: statusHeight,
        navHeight: navHeight
      })
    },
  }
})